from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By

from Foo.capability_json import getDriver
from Foo.login import Login
from util.baseView import BaseView
import time
class SystemSettting(BaseView):
    def __init__(self,driver):
        BaseView.__init__(self,driver)
        self.menu_settings = (By.ID, 'com.sykean.biometrics:id/menu_settings')
        self.address_settings = (By.ID,'com.sykean.biometrics:id/txt_edit_value')
        self.address_dialog = (By.ID,'com.sykean.biometrics:id/edit_dialog_content')
        self.ok_btn = (By.ID,'com.sykean.biometrics:id/btn_dialog_ok')
    def editSetting(self,text):
        driver.implicitly_wait(10)
        self.click_element(*self.menu_settings)
        time.sleep(2)
        try:
            print('--------执行点击输入服务器地址输入框--------------')
            element_input=self.find_element(*self.address_settings)
            self.driver.execute_script("document.getElementById('com.sykean.biometrics:id/txt_edit_value').click()")
            element_input.click()
            print(element_input)
            self.click_element(*self.address_settings)


            print('--------服务器地址输入框打开成功--------------')
        except:
            print('找不到服务器地址输入框')

        try:
            print('-------寻找服务器地址输入框---------')
            driver.implicitly_wait(10)
            self.find_element(*self.address_dialog).send_keys(text)
            time.sleep(2)
            self.click_element(*self.ok_btn)
        except NoSuchElementException as e:
            print(e.args)
        time.sleep(2)


if __name__ == '__main__':
    driver = getDriver()
    Login(driver).login()
    addressArr = ['http://192.168.10.137:888','http://192.168.10.137:8888']
    while True:
        for i in range(2):
            time.sleep(5)
            SystemSettting(driver).editSetting('http://192.168.10.137:8888')
            time.sleep(5)




